import { useData } from './useData'
export const usePageData = () => {
  const state = useState('pageData', () => ({
    index: {},
    language: useCookie('language').value || 'en',
  }))
  const { state: stateData } = useData()

  const langList = computed(() => {
    const data = []
    const keys = Object.keys(stateData.value.configMenu.lang)
    keys.forEach((key) => {
      data.push(stateData.value.configMenu.lang[key].show)
    })
    return data
  })

  const updateLang = (val) => {
    state.value.language = val
    useCookie('language').value = val
    window.location.reload()
  }

  return {
    state,
    langList,
    updateLang,
  }
}
